//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.baidu.lbsapi.auth.tracesdk;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.Signature;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.text.TextUtils;
import android.util.Base64;
import java.io.ByteArrayInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Locale;

class b {
    protected static String a(Context var0) {
        String var1 = var0.getPackageName();
        String var2 = a(var0, var1);
        return var2 + ";" + var1;
    }

    private static String a(Context var0, String var1) {
        String var2 = "";

        try {
            @SuppressLint("WrongConstant") Signature[] var6 = var0.getPackageManager().getPackageInfo(var1, 64).signatures;
            var2 = a((X509Certificate)CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(var6[0].toByteArray())));
        } catch (NameNotFoundException var3) {
            ;
        } catch (CertificateException var4) {
            ;
        }

        StringBuffer var5 = new StringBuffer();

        for(int var7 = 0; var7 < var2.length(); ++var7) {
            var5.append(var2.charAt(var7));
            if(var7 > 0 && var7 % 2 == 1 && var7 < var2.length() - 1) {
                var5.append(":");
            }
        }

        return var5.toString();
    }

    protected static String[] b(Context var0) {
        String[] var1 = null;
        String var2 = var0.getPackageName();
        String[] var4;
        if((var4 = b(var0, var2)) != null && var4.length > 0) {
            var1 = new String[var4.length];

            for(int var3 = 0; var3 < var1.length; ++var3) {
                var1[var3] = var4[var3] + ";" + var2;
                if(com.baidu.lbsapi.auth.tracesdk.a.a) {
                    com.baidu.lbsapi.auth.tracesdk.a.a("mcode" + var1[var3]);
                }
            }
        }

        return var1;
    }

    private static String[] b(Context var0, String var1) {
        String[] var2 = null;

        try {
            Signature[] var9;
            if((var9 = var0.getPackageManager().getPackageInfo(var1, 64).signatures) != null && var9.length > 0) {
                var2 = new String[var9.length];

                for(int var3 = 0; var3 < var9.length; ++var3) {
                    X509Certificate var7 = (X509Certificate)CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(var9[var3].toByteArray()));
                    var2[var3] = a(var7);
                }
            }
        } catch (NameNotFoundException var5) {
            ;
        } catch (CertificateException var6) {
            ;
        }

        String[] var8 = null;
        if(var2 != null && var2.length > 0) {
            var8 = new String[var2.length];

            for(int var10 = 0; var10 < var2.length; ++var10) {
                StringBuffer var11 = new StringBuffer();

                for(int var4 = 0; var4 < var2[var10].length(); ++var4) {
                    var11.append(var2[var10].charAt(var4));
                    if(var4 > 0 && var4 % 2 == 1 && var4 < var2[var10].length() - 1) {
                        var11.append(":");
                    }
                }

                var8[var10] = var11.toString();
            }
        }

        return var8;
    }

    static String a(X509Certificate var0) {
        try {
            return b.a.a(a(var0.getEncoded()));
        } catch (CertificateEncodingException var1) {
            return null;
        }
    }

    static byte[] a(byte[] var0) {
        try {
            return MessageDigest.getInstance("SHA1").digest(var0);
        } catch (NoSuchAlgorithmException var2) {
            return null;
        }
    }

    static String c(Context var0) {
        String var1;
        if((var1 = var0.getSharedPreferences("mac", 0).getString("macaddr", (String)null)) == null) {
            if((var1 = d(var0)) != null) {
                if(!TextUtils.isEmpty(var1 = Base64.encodeToString(var1.getBytes(), 0))) {
                    var0.getSharedPreferences("mac", 0).edit().putString("macaddr", var1).commit();
                }
            } else {
                var1 = "";
            }
        } else {
            var1 = var1;
        }

        if(com.baidu.lbsapi.auth.tracesdk.a.a) {
            com.baidu.lbsapi.auth.tracesdk.a.a("getMacID mac_adress: " + var1);
        }

        return var1;
    }

    static String d(Context var0) {
        String var1 = null;

        try {
            if(c(var0, "android.permission.ACCESS_WIFI_STATE")) {
                WifiInfo var3;
                if(!TextUtils.isEmpty(var1 = (var3 = ((WifiManager)var0.getSystemService("wifi")).getConnectionInfo()).getMacAddress())) {
                    Base64.encode(var1.getBytes(), 0);
                }

                if(com.baidu.lbsapi.auth.tracesdk.a.a) {
                    com.baidu.lbsapi.auth.tracesdk.a.a(String.format("ssid=%s mac=%s", new Object[]{var3.getSSID(), var3.getMacAddress()}));
                }
            } else if(com.baidu.lbsapi.auth.tracesdk.a.a) {
                com.baidu.lbsapi.auth.tracesdk.a.a("You need the android.Manifest.permission.ACCESS_WIFI_STATE permission. Open AndroidManifest.xml and just before the final </manifest> tag add:android.permission.ACCESS_WIFI_STATE");
            }
        } catch (Exception var2) {
            if(com.baidu.lbsapi.auth.tracesdk.a.a) {
                com.baidu.lbsapi.auth.tracesdk.a.a(var2.toString());
            }
        }

        return var1;
    }

    private static boolean c(Context var0, String var1) {
        boolean var2 = var0.checkCallingOrSelfPermission(var1) != -1;
        if(com.baidu.lbsapi.auth.tracesdk.a.a) {
            com.baidu.lbsapi.auth.tracesdk.a.a("hasPermission " + var2 + " | " + var1);
        }

        return var2;
    }

    static String a() {
        return Locale.getDefault().getLanguage();
    }

    static class a {
        public static String a(byte[] var0) {
            char[] var1 = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
            StringBuilder var2 = new StringBuilder(var0.length << 1);

            for(int var3 = 0; var3 < var0.length; ++var3) {
                var2.append(var1[(var0[var3] & 240) >> 4]);
                var2.append(var1[var0[var3] & 15]);
            }

            return var2.toString();
        }
    }
}
